package pers.muci.es.doc;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Arrays;

/**
 * @ClassName DocInsert
 * @Description TODO
 * @Author muci
 * @Date 2021/12/21 21:59
 * @Version 1.0
 **/
public class DocDeleteBatch {
    public static void main(String[] args) throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("106.14.15.56", 9200, "http"))
        );

        BulkRequest request = new BulkRequest();
        DeleteRequest first = new DeleteRequest().index("user").id("1001");
        DeleteRequest second = new DeleteRequest().index("user").id("1002");
        DeleteRequest third = new DeleteRequest().index("user").id("1003");
        request.add(Arrays.asList(first, second, third));
        BulkResponse response = client.bulk(request, RequestOptions.DEFAULT);
        System.out.println(response.getItems());
        System.out.println(response.getTook());

        client.close();
    }
}
